<!--
 * @Descripttion: 其他设置
 * @Author: xiao li
 * @Date: 2020-12-07 10:50:31
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-28 10:57:19
-->
<template>
  <div class="lb-deal-set">
    <top-nav />
    <div class="page-main">
      <div style="height:20px"></div>
      <el-form @submit.native.prevent :model="subForm" :rules='subFormRules' ref='subForm'
        label-width="100px">
        <el-form-item label="订单超时" prop="order_over_time">
          <el-input v-model.number="subForm.order_over_time" placeholder="请输入秒数"></el-input>
          <lb-tool-tips>订单未支付超时时间, 超时将自动取消订单, 单位: 秒</lb-tool-tips>
        </el-form-item>
        <el-form-item>
          <lb-button type='primary' @click="submitForm()">{{$t('action.submit')}}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      subForm: {
        order_over_time: 0
      },
      subFormRules: {
        order_over_time: {
          required: true,
          type: 'number',
          message: '请输入数字',
          trigger: 'blur'
        }
      }
    }
  },
  components: {
  },
  created () {
    this.getSettingInfo()
  },
  methods: {
    async getSettingInfo () {
      let {code, data} = await this.$api.payclassConfigInfo()
      if (code !== 200) return
      let arr = ['order_over_time',
        'order_success_time',
        'order_refund_time',
        'refund_success_time' ]
      arr.map(item => {
        data[item] = data[item] * 1
      })
      for (let key in this.subForm) {
        this.subForm[key] = data[key]
      }
      let checkSend = []
      this.sendList.map(item => {
        if (data[item.key] === 1) {
          checkSend.push(item.title)
        }
      })
      this.checkSend = checkSend
    },
    submitForm () {
      let subForm = JSON.parse(JSON.stringify(this.subForm))
      let formArr = ['subForm']
      if (subForm.dada_send === 1) {
        formArr.push('dadaForm')
      }
      let flag = true
      for (let i = 0, len = formArr.length; i < len; i++) {
        this.$refs[formArr[i]].validate(valid => {
          if (!valid) {
            flag = false
            return false
          }
        })
      }
      if (flag) {
        this.$api.payclassConfigUpdate(subForm).then(res => {
          if (res.code === 200) {
            this.$message.success(this.$t('tips.successSub'))
          }
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .lb-deal-set {
    width: 100%;

    .page-main {
      padding: 20px;

      .el-input {
        width: 300px;
      }
    }
  }
</style>
